package thread;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class TimeHandler implements InvocationHandler {
    private Object target;
    public TimeHandler(Object t){
        this.target=t;
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("当前正在执行:"+method.getName());
        long start=System.nanoTime();
        Object o=method.invoke(target,args);
        long end=System.nanoTime();
        System.out.println(method.getName()+"执行花费了:"+(end-start)+"纳秒");
        return o;
    }
    public Object getProxy(){
        return Proxy.newProxyInstance(target.getClass().getClassLoader(),target.getClass().getInterfaces(),this);
    }
}
